﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using FairyGUI;
using UnityEngine;

namespace MDFGame
{
    public class DescribeUIView
    {
        private GComponent MainUI;
        private Controller ViewControl;
        private GRichTextField DescribeField;

        public void Create(GComponent UI)
        {
            MainUI = UI;
            DescribeField = MainUI.GetChild("n4").asRichTextField;
            MainUI.GetController("DV").selectedIndex = 0;

            MainUI.SetPivot(0.5f,0.5f,true);
            MainUI.SetXY(-MainUI.x,-MainUI.y);
            MainUI.visible = false;
        }

        public void MoveView(GComponent targetCard)
        {
            //卡片悬浮中需要调整弹出框的位置,避免出界，默认弹出框轴心中点
            float _px = (MainUI.width * 2.5f + MainUI.x > GRoot.inst.width) ? (MainUI.x - MainUI.width * 1.5f) : (MainUI.x + MainUI.width * 1.5f);
            float _py = (MainUI.height + MainUI.y > GRoot.inst.width) ? (MainUI.y - MainUI.height) : (MainUI.y + MainUI.height);
            MainUI.SetXY(_px, _py);
        }
        public void ShowView(string text = null)
        {
            if (text != null)
            {
                DescribeField.text = text;
            }
            MainUI.visible = true;
            /*展开动画*/
            ViewControl.selectedIndex = 1;
        }

        public void HideView()
        {
            ViewControl.selectedIndex = 0;
            MainUI.visible = false;
        }
    }
}
